<!DOCTYPE html>
<html lang="en">

<head>
    <link rel="stylesheet" href="/static/plugins/layui/css/layui.css">
    <script type="text/javascript" src="/static/plugins/layui/layui.js"></script>
    <style>
        .header span {
            background: #009680;
            font-size: 18px;
            margin-left: 10px;
            padding: 5px;
        }
        
        .header button {
            float: right;
            margin-right: 10px;
        }
    </style>
</head>

<body style="padding: 10px;">
    <div class="header">
        <span>影视列表</span>
        <button class="layui-btn  layui-btn-warm layui-btn-sm" onclick="add()">添加</button>
        <hr style="border:solid 1px;">
    </div>

    <div class="layui-form-item">
        <div class="layui-input-inline">
            <input type="text" id="find" class="layui-input" value="{$data.find}">
        </div>
        <button class="layui-btn layui-btn-primary" onclick="search()"><i class="layui-icon">&#xe615;</i>搜索</button>
    </div>
    <table class="layui-table">
        <thead>
            <tr>
                <th>ID</th>
                <th>频道</th>
                <th>资费</th>
                <th>地区</th>
                <th>名称</th>
                <th>PV</th>
                <th>评分</th>
                <th>状态</th>
                <th>添加时间</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            {volist name="data.data.lists" id="vo"}
            <tr>
                <th>{$vo.id}</th>
                <th>{:isset($data['labels'][$vo.channel_id])?$data['labels'][$vo.channel_id]['title']:''}</th>
                <th>{:isset($data['labels'][$vo.charge_id])?$data['labels'][$vo.charge_id]['title']:''}</th>
                <th>{:isset($data['labels'][$vo.area_id])?$data['labels'][$vo.area_id]['title']:''}</th>
                <th>{$vo.title}</th>
                <th>{$vo.pv}</th>
                <th>{$vo.score}</th>
                <th>{$vo.status==0?'<span style="color: red;">下线</span>':'发布'}</th>
                <th>{:date('Y-m-d H:i:s',$vo.add_time)}</th>
                <th>
                    <button class="layui-btn layui-btn-xs" onclick="add({$vo.id})">编辑</button>
                    <button class="layui-btn layui-btn-xs layui-btn-danger" onclick="del({$vo.id})">删除</button>
                </th>
            </tr>
            {/volist}


        </tbody>
    </table>
    {//$data.data.pages}
    <div id='pages'></div>

    <script>
        layui.use(['layer','laypage'], function() {
            layer = layui.layer;
            $ = layui.jquery;
            laypage=layui.laypage;

            //执行一个laypage实例
            laypage.render({
                elem: 'pages' //注意，这里的 pages 是 ID，不用加 # 号
                ,count: {$data.data.total} //数据总数，从服务端得到
                ,limit:{$data.pageSize}//每页显示的条数
                ,curr:{$data.page}//起始页
                ,jump: function(obj, first){
                    //obj包含了当前分页的所有参数，比如：
                    //首次不执行
                    if(!first){
                        search(obj.curr);
                    }
                }
            });


        });

        //搜索
        function search(currPage){
            find=$.trim($('#find').val());
            url="/admins.php/admins/video/index?page="+currPage;
            if(find){
                url+='&find='+find;
            }
            window.location.href=url;


        }
        

        //添加编辑

        function add(id) {
            layer.open({
                type: 2,
                title: id>0?'编辑影片':'添加影片',
                shade: 0.8,
                area: ['700px', '550px'],
                content: '/admins.php/admins/Video/add?id='+id
            });

        }

        //删除

        function del(id) {
            layer.confirm('确定删除？', {
              btn: ['确定','取消'] 
            }, function(){
                $.post('/admins.php/admins/Video/delete',{'id':id},function(res){
                    if(res.code>0){
                        layer.alert('删除失败',{'icon':2});
                   }else{
                    layer.msg('删除成功',{'icon':1});
                    setTimeout(function(){
                        window.location.reload();
                    },1000);
                   };

                })
              
            }, function(){
              },'json');
        }

    </script>



</body>

</html>